//
//  VideoViewController.m
//  GGTV
//
//  Created by apple on 15/10/22.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "VideoViewController.h"
#import "CCDefine.h"
#import "UserUploadClass.h"
#import "AdView.h"


@interface VideoViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate>
@property(strong,nonatomic) NSMutableArray *userUploadArray;
@property(strong,nonatomic) UITableView    *tableView;
@property(strong,nonatomic) AdView         *adView;
@property(assign,nonatomic) NSInteger      page;
@end

@implementation VideoViewController

- (void)addHeader
{
    __unsafe_unretained typeof(self) vc = self;
    // 添加下拉刷新头部控件
    [self.tableView addHeaderWithCallback:^{
        _page = 1;
        //[vc getSchoolChatData];
    }];
    [self.tableView headerBeginRefreshing];
}

-(void)initSubView
{
    self.view.backgroundColor = [UIColor whiteColor];
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, kscreenWith, kscreenHeight)
                                                style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.view addSubview:self.tableView];
    
    // 2.集成刷新控件
    [self addHeader];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self initSubView];
    
    
    
    NSString *urlString = @"https://openapi.youku.com/v2/videos/by_user.json";
    
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    [dict setValue:youkuID forKey:@"client_id"];
    [dict setValue:@"published" forKey:@"orderby"];
    [dict setValue:@"Dota情书" forKey:@"user_name"];
    
    [CCTools JSONDataToDictionaryWithUrl:urlString dictinory:dict success:^(id data) {
        NSLog(@"%@",data);
        
        if (!_userUploadArray) {
            _userUploadArray = [NSMutableArray array];
        }
        if (_userUploadArray.count > 0) {
            [_userUploadArray removeAllObjects];
        }

        for (NSDictionary *temp in [data objectForKey:@"videos"]) {
            UserUploadClass *userUpload = [UserUploadClass modelWithDictionary:temp];
            [CCTools setCustomObjToUserDefault:userUpload key:@"123"];
            UserUploadClass *userLoad = [CCTools getCustomObjFromUserDefault:@"123"];
            [_userUploadArray addObject:userLoad];
        }
        [self.tableView reloadData];
    } fail:^(NSError *error) {
        
    }];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark-
#pragma mark-网络请求
-(void)getVideoRequest
{
    
}


#pragma mark-
#pragma mark-tableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _userUploadArray.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *cellIndntifier = @"cellIdentifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndntifier];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:cellIndntifier];
    }
    UserUploadClass *userUpload = [[UserUploadClass alloc]init];
    userUpload = _userUploadArray[indexPath.row];
    cell.textLabel.text = [NSString stringWithFormat:@"%@",userUpload.title];
    return cell;
}



/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
